package com.luck;

import com.luck.api.ThinkWordsManager;
import com.luck.model.po.ThinkWords;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by Hua wb on 2018/9/21.
 */
@Controller
@RequestMapping("/thinkWords")
public class ThinkWordsController {
    @Autowired
    private ThinkWordsManager thinkWordsManager;

    /**
     * 快捷添加
     * 只能允许登录过的能够发表
     * @param content
     * @param httpSession
     * @return
     */
    @RequestMapping("/add/{content}")
    public String add(@PathVariable String content, HttpSession httpSession) {
        ThinkWords thinkWords = new ThinkWords();
        thinkWords.setContent(content);
        Integer userId = (Integer) httpSession.getAttribute("userId");
        if (userId == null || userId == 0) {
            return "redirect:/home";
        }
        thinkWords.setUserId(userId);
        thinkWordsManager.addThinkWords(thinkWords);
        return "redirect:/home";
    }

    /**
     * 添加文章
     * @param thinkWords
     * @return
     */
    @RequestMapping("/addMax/{content}")
    public String addMax(ThinkWords thinkWords) {
        thinkWordsManager.addThinkWords(thinkWords);
        return "redirect:/home";
    }

}
